package com.chengzhi;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@SpringBootApplication
@EnableDiscoveryClient
public class Application {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private DiscoveryClient discoveryClient;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @GetMapping("service")
    public Object getServiceList() {
        return discoveryClient.getServices();
    }

    @GetMapping("/actuator/health")
    public Object health() {
        return "OK";
    }

    @GetMapping("/hello")
    public void print() {
        logger.info("print");
//        restTemplate.getForObject("http://disruptor-client/hello", String.class);
//        restTemplate.getForObject("http://127.0.0.1:9988/hello", String.class);
        System.out.println("hello trace");
    }
}
